package Server;

import Data.MassageData;

import java.sql.*;

public class InsertMassageToSql {
    String url = "jdbc:mysql://127.0.0.1:3306/nox?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8";
    String user = "root";
    String password = "Mi20030610.";
    String sql="INSERT INTO massagelist (sender_id,receiver_id,is_file,content,date) VALUES(?,?,0,?,?);";
    private MassageData massageData;

    public InsertMassageToSql(MassageData massageData) {
        this.massageData = massageData;
    }
    public boolean insertSql() throws SQLException {
        Connection Conn = DriverManager.getConnection(url, user, password);
        PreparedStatement operation = null;

        operation=Conn.prepareStatement(sql);
        operation.setString(1,massageData.getSender());
        operation.setString(2,massageData.getReceiver());
        operation.setString(3,massageData.getContent());
        operation.setTimestamp(4, massageData.getTimestamp());
        int k=operation.executeUpdate();
        if(k>0)
        {
            return true;
        }
        return false;
    }
}

